package com.example.login.Controller;

import com.example.login.Mapper.GoodsMap;
import com.example.login.Pojo.PCGoods;
import com.example.login.Pojo.Seller;
import com.example.login.Pojo.mobileGoods;
import com.example.login.Pojo.mp3Goods;
import com.example.login.Service.SellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class MerchantController {
    @Autowired
    SellerService ss;
    @GetMapping("/seller")
    public String jump()
    {
        return "/卖家登录";
    }
    @Autowired
    GoodsMap goodsMap;
    @GetMapping("/sellerLogin")
    public String login(@RequestParam("SellerAccount")String username,
                        @RequestParam("SellerPassword")String password, Model model,
                        HttpSession session)
    {
        Seller seller=ss.isSeller(username,password);
        if(seller==null) {
            model.addAttribute("msg","用户名或密码错误");
            return "卖家登录";
        }
        else{
            List<mp3Goods> mp3= goodsMap.getMp3Goods();
            List<PCGoods> pc=goodsMap.getPCGoods();
            List<mobileGoods> mobile=goodsMap.getMobileGoods();
            model.addAttribute("mp3Goods",mp3);
            model.addAttribute("pcGoods",pc);
            model.addAttribute("mobileGoods",mobile);
            session.setAttribute("seller",seller);
            return "/商家中心/查看商品";
        }

    }
    @RequestMapping("/MerchantRegister")
    public String MerRegister(@RequestParam("MerchantName") String name,@RequestParam("StoreName") String store,
                              @RequestParam("MerchantPassword") String password, Model model){
        ss.Registe(name,password,store);
        return "登录";
    }
}
